
/***
 * Copyright (c) 2012 Centrodata Sistemas e Automação - www.centrodata.com.br
 * All rights reserved.
 */

package br.com.centrodata.dao;

import br.com.caelum.vraptor.ioc.Component;
import br.com.centrodata.model.User;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author João Fernandes Lima Neto
 */
@Component
public class DefaultUserDao extends DefaultGenericDao<User> implements UserDao{

    public DefaultUserDao(Session session) {
        super(session);
    }
    
    @Override
    public List<User> searchWithName(String name) {
        return this.getSession().createCriteria(User.class)
                .add(Restrictions.ilike("nome", name)).list();
    }

    @Override
    public User login(String login, String senha) {
        return (User) this.getSession().createCriteria(User.class).add(Restrictions.and(Restrictions.eq("login", login), Restrictions.eq("senha", senha)) ).uniqueResult();
    }

    @Override
    public boolean existisUserWithLogin(String login) {
        return this.getSession().createCriteria(User.class).add(Restrictions.eq("login", login)).uniqueResult() != null;
    }

}
